<?php
$loader->requireOnce('includes/ServiceDiscount/TicketItemPayment.class.php');

class ServiceItemPayment extends TicketItemPayment {
			
	function __construct($discountBehaviour) {
		parent::__construct($discountBehaviour);
	}
	
	/**
	 * Calculate prices for a ticket item with type = 'service'
	 *
	 * @param int $ticketItemId
	 * @param String $insuranceType
	 * @param array $additionalData
	 * 			[real_payment]
	 */
	public function add($ticketItemId, $insuranceType) {
		$ti = Celini::newORDO('TicketItem', $ticketItemId);				
		$serviceId = $ti->get('item_id');
		/**
		 * original_price
		 * patient_price
		 * insurance_price
		 */		
		$price = $this->getServicePrice($serviceId, $insuranceType);			
		$this->calculate($serviceId, $price);
	}
	
	public function update($ticketItemId) {
		$ti = Celini::newORDO('TicketItem', $ticketItemId);				
		$serviceId = $ti->get('item_id');
		/**
		 * original_price
		 * patient_price
		 * insurance_price
		 */		
		$price = $this->getTicketItemPrice($ticketItemId);			
		$this->calculate($serviceId, $price);
	}
	
	private function calculate($serviceId, $price) {
		// discount on saleProgram
		$saleDiscount = $this->discountBehaviour->discountOnSaleProgram($serviceId, $price['patient_price']);
		// update discount 
		$price['discount'] = $saleDiscount;		
		$this->result = $price;	
	}
	
}
?>